<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="100px">
      <el-form-item label="工单编号" prop="wxCode">
        <el-input
          v-model="queryParams.wxCode"
          placeholder="请输入工单编号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
         <el-form-item label="维修站名称" prop="wxCode">
        <el-input
          v-model="queryParams.wxCode"
          placeholder="请输入维修站名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="车牌号" prop="wxUnit">
        <el-input
          v-model="queryParams.wxCode"
          placeholder="请输入车牌号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="车架号" prop="wxUnit">
        <el-input
          v-model="queryParams.wxCode"
          placeholder="请输入车架号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="发动机号" prop="wxUnit">
        <el-input
          v-model="queryParams.wxCode"
          placeholder="请输入发动机号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
       <el-form-item label="燃料类型" prop="wxUnit">
        <el-input
          v-model="queryParams.wxCode"
          placeholder="请输入燃料类型"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="营运类型" prop="wxUnit">
        <el-input
          v-model="queryParams.wxCode"
          placeholder="请输入营运类型"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="车辆类型" prop="wxUnit">
        <el-input
          v-model="queryParams.wxCode"
          placeholder="请输入车辆类型"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="所属地区" prop="wxUnit">
        <el-input
          v-model="queryParams.wxCode"
          placeholder="请输入所属地区"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="工单创建日期" prop="wxUnit">
        <el-date-picker
          v-model="dateRange"
          type="daterange"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          value-format="yyyy-MM-dd">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['vehicleservice:secondary:remove']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table  border v-loading="loading" :data="orderList">
      <el-table-column label="合同编号" align="center" prop="htnum" />
      <el-table-column label="道路运输证号" align="center" prop="yyznum" />
      <el-table-column label="车架号" align="center" prop="vin" />
      <el-table-column label="车牌号" align="center" prop="brand" />
      <el-table-column label="托修方" align="center" prop="txunit" />
      <el-table-column label="托修方电话" align="center" prop="txtel" />
      <el-table-column label="车型" align="center" prop="vehicletype" />
      <el-table-column label="所属地区" align="center" prop="orgName" />
      <el-table-column label="检验单位" align="center" prop="checkunit" />
      <el-table-column label="检验员" align="center" prop="checkPerson" />
      <el-table-column label="检验结论" align="center" prop="judge" />
      <el-table-column label="检验日期" align="center" prop="checkdate" width="180"/>
      <el-table-column label="创建日期" align="center" prop="createTime" width="180"/>
      <el-table-column label="操作" width="100" fixed="right" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            @click="open=true"
            size="mini"
            type="text"
            icon="el-icon-tickets"
          >检验报告单</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <el-dialog title="检验报告单" :visible.sync="open" width="70%" append-to-body>
      <div>
        <!-- <vue-pdf src="https://m.azdzkj.com/prod-api/profile/upload/2025/10/31/1.pdf" width="100%" height="600px"></vue-pdf> -->
        <iframe src="https://m.azdzkj.com/prod-api/profile/upload/2025/10/31/1.pdf" width="100%" height="600px"></iframe>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listSecondary, getSecondary, delSecondary, addSecondary, updateSecondary, controlShow,updateStatus,wxUnitList } from "@/api/maintenanceenterprise/secondarysite";
import { getToken } from "@/utils/auth";
import VuePdf from 'vue-pdf';
export default {
  name: "Secondary",
  components: { VuePdf },
  data() {
    return {
      open: false,
      dateRange: [new Date(2025, 9, 1, 8, 0), new Date(2025, 10, 1, 8, 0)],
      headers: {
        Authorization: "Bearer " + getToken(),
      },
      controlShow: false,
      props: {
        label: "name",
        value: "code",
        children: "chridrenList"
      },
      wxUnitList: [],
      options: [],
      fileList: [],
      accept: ".xls,.xlsx",
      importUrl: process.env.VUE_APP_BASE_API + "/vehicleservice/secondary/import/data",
      openImportData: false,
      // 遮罩层
      loading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 4,
      // 汽车检测-二级维护站表格数据
      orderList: [
        {
          htnum: 'WXSECONDARY202212120001',
          yyznum: '202212120001',
          vin: '202212120001',
          orgName: '兰山区',
          brand: '鲁A12345',
          txunit: '杨汽车维修',
          txtel: '13806355890',
          vehicletype: '大型车',
          checkunit: '***监测站',
          checkPerson: '杨***',
          judge: '合格',
          checkdate:"2025-10-20",
          createTime:'2025-10-20 11:00:00'
        }
      ],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        vehicleType: null,
        plateNo: "",
        whDate: null,
        orgCode: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        wxUnit: [
          { required: true, message: '请输入维护站名称', trigger: 'blur' },
        ],
        wxAddr: [
          { required: true, message: '请输入维护站地址', trigger: 'blur' },
        ],
        wxPerson: [
          { required: true, message: '请输入联系人', trigger: 'blur' },
        ],
        wxTel: [
          { required: true, message: '请输入联系人电话', trigger: 'blur' },
        ],
        creditCode: [
          { required: true, message: '请输入社会统一代码', trigger: 'blur' },
        ],
        legalPerson: [
          { required: true, message: '请输入法人', trigger: 'blur' },
        ],
        legalTel: [
          { required: true, message: '请输入法人电话', trigger: 'blur' },
        ],
        businessScope: [
          { required: true, message: '请输入经营范围', trigger: 'blur' }
        ],
        enterpriseType: [
          {required: true, message: '请选择企业类型', trigger: 'change'}
        ]
      }
    };
  },
  methods: {
    checkDataReslutHandle(){

    },
    handleClose(){
      this.fileList = []
    },
    handleRemove(file, fileList) {
      console.log(file, fileList);
    },
    handlePreview(file) {
      console.log(file);
    },
    handleExceed(files, fileList) {
      this.$message.warning(`只能上传一个文件`);
    },
    beforeRemove(file, fileList) {
      return this.$confirm(`确定移除 ${ file.name }？`);
    },
    uploadSuccess(response, file, fileList){
      if(response.code === 200){
        this.$message.success(response.msg);
        this.openImportData = false;
        this.fileList = fileList;
        this.getList();
      }else {
        this.$message.error(response.msg);
      }
    },

    openImport(){
      this.openImportData = true;
      this.fileList = [];
    },
    /** 查询汽车检测-二级维护站列表 */
    getList() {
      this.loading = true;
      listSecondary(this.queryParams).then(response => {
        this.orderList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        wxCode: null,
        wxUnit: null,
        wxAddr: null,
        wxPerson: null,
        wxTel: null,
        creditCode: null,
        licensepic: null,
        legalPerson: null,
        legalTel: null,
        businessScope: null,
        orgCode: null,
        createTime: null,
        updateTime: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      if (this.queryParams.orgCode) {
        this.queryParams.orgCode = this.queryParams.orgCodes.toString();
      }

      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.$router.push('/maintenanceorder/addorder/index')
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getSecondary(id).then(response => {
        this.form = response.data;
        this.form.orgCodes = response.data.orgCode;
        this.open = true;
        this.title = "修改汽车检测-二级维护站";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          this.form.orgCode = this.form.orgCodes.toString();
          if (this.form.id != null) {
            updateSecondary(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addSecondary(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除？').then(function() {
        return delSecondary(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('vehicleservice/secondary/export', {
        ...this.queryParams
      }, `secondary_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
